#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require 'fileutils'
require "#{LKP_SRC}/lib/statistics"
require "#{LKP_SRC}/lib/string_ext"

results = {}
results['test'] = ''
results['val'] = []

def show_one(new_test, results)
  printf "%s: %d\n", results['test'], results['val'].average unless results['test'].empty? || results['val'].empty?
  results['test'] = new_test
  results['val'] = []
end

while (line = $stdin.gets)
  line = line.resolve_invalid_bytes

  case line
  when /testing speed of (.*)$/
    show_one($1.tr(' ', '.'), results)
  when /\d+ operations in (\d+) seconds \((\d+) bytes\)/
    bps = $2.to_i / $1.to_i
    results['val'] << bps
  when /\d+ opers\/sec, +(\d+) bytes\/sec/
    bps = $1.to_i
    results['val'] << bps
  end
end

show_one('', results)
